<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE HTML >
<%@include file="/WEB-INF/jsp/include/background.jsp"%>
<%
request.setCharacterEncoding("UTF-8");
String htmlData = request.getParameter("info") != null ? request.getParameter("info") : "";
%>
<html>
<head>
<meta charset=UTF-8>
<title>教师详情页面</title>
<link rel="stylesheet" type="text/css" href="<%=css%>/common.css"/>
<link rel="stylesheet" type="text/css" href="<%=css%>/main.css"/>
<link rel="stylesheet" href="<%=kePath %>/themes/default/default.css" />
<link rel="stylesheet" href="<%=kePath %>/plugins/code/prettify.css" />
<script charset="utf-8" src="<%=kePath %>/kindeditor.js"></script>
<script charset="utf-8" src="<%=kePath %>/lang/zh_CN.js"></script>
<script charset="utf-8" src="<%=kePath %>/plugins/code/prettify.js"></script>
<script charset="utf-8" src="<%=kePath %>/plugins/autoheight/autoheight.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	//返回按钮
	$("#goBack").click(function(){
		$("#form2").submit();
	});
	
	//视频预览功能
	$("#videoPreview").click(function(){
		var videoPath = $("#videopath").val();
		art.dialog.open("<%=pre%>/teacher/vedioPreview<%=suf%>?vp=" + videoPath,{
			width:650,
		    height:370,
			title:"教师视频简介"
		});
	});
	
	//保存按钮
	$("#saveButton").click(function() {
		var id = $("#id").val();
		var name = $("#name").val();
		var sex = $("#sex").val();
		var headpath = $("#headpath").val();
		var phone = $("#phone").val();
		var videopath = $("#videopath").val();
		var school = $("#school").val();
		var recommend = $("input[name='recommend']:checked").val();		
		$.ajax({
			url : "<%=pre%>/b_excellentstudent/update<%=suf%>",
			type : 'post',
			dataType : 'html',
			data : {id:id,name:name,sex:sex,phone:phone,school:school,videopath:videopath,headpath:headpath},
			success : function(data, status) {
				if (status == 'success') {
					if (data == '1') {
						art.dialog.tips('<span style="color:#f00">编辑成功！</span>', 1.5);
					} else {
						art.dialog.tips('<span style="color:#f00">编辑失败！</span>', 1);
					}
				}
			},
			error : function(xhr, textStatus,
					errorThrown) {
				art.dialog.tips('<span style="color:#f00">插入失败！</span>', 1);
			}
		});
	});
	
	//上传图片
	$("#uploadFile").live('change',function(){
		var picFile = $("#uploadFile").val();
		var wjjname = "excstu";
		if(picFile == ""){
			art.dialog.alert("请选择文件!");
			return;
		}
		else{
			var strFilter = ".jpeg|.gif|.jpg|.png|";
			if(picFile.indexOf(".") > -1){
				var p = picFile.lastIndexOf(".");
				var strPostfix = picFile.substring(p,picFile.length) + '|';
				strPostfix = strPostfix.toLowerCase();
				if(strFilter.indexOf(strPostfix) > -1){
					$.ajaxFileUpload({
						url: '<%=pre%>/b_com/fileupload<%=suf%>', 
						data:{wjjname:wjjname},
						type: 'post',
						fileElementId: 'uploadFile',
						dataType:'json', //返回值类型，一般设置为json、application/json
						success: function(data, status){ 
				            	if(data.ret == 1){
				            		$("#headpath").val(data.path);
				            		$("#imgheadpath").attr("src","<%=upload%>/"+ data.path);
				            	}
				            	else{
				            		art.dialog.alert("上传失败！");
				            	}
				            },
				            error: function(data, status, e){ 
				            	art.dialog.tips('<span style="color:#f00">上传失败，请重传！</span>', 1);
				            }
					});
				}else{
					art.dialog.alert("请选择：图片格式的文件！");
				}
			}
		}
	});
});
KindEditor.ready(function(K) {
	var editor = K.create('textarea[name="info"]', {
		cssPath : '<%=kePath %>/plugins/code/prettify.css',
		uploadJson : '<%=kePath %>/jsp/upload_json.jsp',
		fileManagerJson : '<%=kePath %>/jsp/file_manager_json.jsp',
		autoHeightMode:true
	});
	prettyPrint();
	
	$("#saveInfo").click(function(){
		editor.sync();
		var info = $('#info').val();
		var id=$("#id").val();
		$.ajax({
			url : "<%=pre%>/b_excellentstudent/update<%=suf%>",
			type : 'post',
			dataType : 'html',
			data : {id:id,info:info},
			success : function(data, status) {
				if (status == 'success') {
					if (data == '1') {
						art.dialog.tips('<span style="color:#f00">保存成功！</span>', 1.5);
					} else {
						art.dialog.tips('<span style="color:#f00">保存失败！</span>', 1);
					}
				}
			},
			error : function(xhr, textStatus,
					errorThrown) {
				art.dialog.tips('<span style="color:#f00">保存失败！</span>', 1);
			}
		});
	});
});
</script>
</head>
<body>
<div class="crumb-wrap">
	<div class="crumb-list">
		<i class="icon-font"></i>
		<a href="index.html">首页</a>
		<span class="crumb-step">&gt;</span>
		<span class="crumb-name">优秀学生管理</span>
		<span class="crumb-step">&gt;</span>
		<span class="crumb-name">优秀学生编辑</span>
	</div>
</div>
<form id="form2" action="<%=pre%>/b_excellentstudent/index<%=suf%>" method="post"></form>
<div class="result-wrap">
	<div>
		<input type="hidden" id="id" name="id" value="${bean.id}" />
	</div>
	<div class="result-content">
		<table class="insert-tab" width="100%">
			<tr>
				<td style="width:12%">教师姓名：</td>
				<td style="width:40%">
					<input id="name" name="name" type="text" style="width:150px" value="${bean.name }" />
					<span class="red" id="nametip">*</span>
				</td>
				<td style="width:10%">性别:</td>
				<td style="width:40%">
					<select id="sex" name="sex">
						<option <c:if test="${bean.sex == '男'}">selected="selected"</c:if>>男</option>
						<option <c:if test="${bean.sex == '女'}">selected="selected"</c:if>>女</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>电话：</td>
				<td>
					<input type="text" name="phone" id="phone" style="width:150px" value="${bean.phone }"/>
				</td>
				<td>学校：</td>
				<td>
					<input type="text" name="school" id="school" style="width:300px" value="${bean.school }" />
				</td>
			</tr>
			<tr>
				<td>视频地址：</td>
				<td colspan="3">
					<input type="text" id="videopath" name="videopath" value="${bean.videopath }" style="width:80%"/>
					<span style="color:red">*</span>
					<input type="button" value="视频预览" id="videoPreview" />
				</td>
			</tr>
			<tr >
				<td>推荐到首页：</td>
				<td colspan="3">
					<input type="radio" value="2" name="recommend" <c:if test="${bean.recommend == 2 }">checked="true"</c:if>>否
					<input type="radio" value="1" name="recommend" <c:if test="${bean.recommend == 1 }">checked="true"</c:if>>是
				</td>
			</tr>
			<tr>
				<td>选择头像：</td>
				<td colspan=3>
					<input id="headFile" name= "headFile" type="file" style="line-height:140px" /> 
					<img src="<%=upload%>/${bean.headpath}" width="120px" height="120px"/>
					<span style="color:red">请选择220*220(px)大小的图像</span>
					<input type="hidden" id="headpath" value="${bean.headpath }">
				</td>
			</tr>	
			<tr>
				<td>
					<input type="button" value="保存" class="button" id="saveButton" />
					<a href="<%=pre%>/b_excellentstudent/index<%=suf%>" style="padding-left:10px">返回</a>
				</td>
				<td colspan=3>
					<label style="color:red">
						<c:if test="${tip == 'ok' }">保存成功！</c:if>
						<c:if test="${tip == 'error' }">保存失败！</c:if>
					</label>
				</td>
			</tr>										
		</table>
	</div>
</div>
<div class="result-wrap">
	<div class="result-title">
	    <div class="result-list">
	    	优秀学员详情
	    </div>
	    <div>
	    	<%=htmlData%>
	    	<textarea id="info" name="info" style="width:100%;height:300px;">
				<%=htmlspecialchars(htmlData)%>${bean.info}
			</textarea>
	    </div>
	    <div style="margin-bottom:30px">
	    	<input type="button" value="保存" id="saveInfo"/>
	    	<a href="<%=pre%>/b_excellentstudent/index<%=suf%>" style="padding-left:10px">返回</a>
	    </div>
	</div>
</div>
<%!
private String htmlspecialchars(String str) {
	str = str.replaceAll("&", "&amp;");
	str = str.replaceAll("<", "&lt;");
	str = str.replaceAll(">", "&gt;");
	str = str.replaceAll("\"", "&quot;");
	return str;
}
%>
</body>
</html>